import Request from "@/sdk/pocky-request/index.js"

export default {

	getData() {
		let r = Request();
		let instance = r.request({
			url: '/user/getUserInfo',
			method: 'get',
			params: {
				name: 'xxx',
				age: 20
			},
		});
		return instance;
	},
	/**
	 * @description 获取更新接口
	 * @return {Primes}
	 */
	getUpdata() {
		
		let _pt=uni.getSystemInfoSync().platform.toLocaleUpperCase()
		console.log("渠道:"+plus.runtime.channel);
		let _cn=plus.runtime.channel;
		if(_pt=='IOS'){
			_cn=10000
		}
		return Request().post('/common/check_version.do', {
			data: {
				channel:_cn,		//渠道号plus.runtime.channel
				platform: _pt,						//平台 ios or android 大写

			}
		});
	},
	/**
	 * @description 多图上传 同步函数,第一张上传成功后才会上传后面一张
	 * @param {Array} fileArray
	 * @return {Array} 上传成功后返回的结果
	 * fileArray格式
	 * [{name:'file',uri:'本地选择图片的路径'},...]
	 */
	async uploadImg(fileArray) {
		let _this = this;
		console.log(fileArray);
		uni.showLoading({
			title: '图片上传中',
			mask: false
		});
		let result = [];
		for (let i = 0; i < fileArray.length; i++) {
			if (fileArray[i]) {
				const ret = await _this.uploadSingleImg(fileArray[i].uri, fileArray[i].name).then(res => {
					console.log(res.data.data.url);
					result[i] = res.data.data.url
				})
			}

		}
		uni.hideLoading()
		return result;

	},
	/**
	 * @description 单图上传
	 * @param {Object} file 文件路径
	 * @param {Object} name 文件名  目前必须为file
	 */
	uploadSingleImg(file, name) {
		return new Promise((resolve) => {
			if(file.indexOf("blob:")>-1 || file.indexOf("file:")>-1){
				const uploadTask = uni.uploadFile({
					// url: 'http://trainingtest.7637.com:8088/training-merchant/file/upload.do',
					url:'http://b.de123.com/training-merchant/file/upload.do',
					
					filePath: file,
					name: name,
					formData: {
						session_id: "123123", //用户登录成功返回的会话标识
						type: 1, //1图片 2视频
						biz: 2 //1评价内容 2个人头像  
					},
					success: (uploadFileRes) => {
						console.log(uploadFileRes);
						uploadFileRes.data = JSON.parse(uploadFileRes.data)
						console.log(uploadFileRes);
						resolve(uploadFileRes);
					},
					fail: (err) => {
						uni.showToast({
							title: '图片上传失败,'+err
						});
					}
				});
				uploadTask.onProgressUpdate((res) => {
					uni.$emit("setPrs",res)
					       
				});
			}else{
				resolve({
					data:{
						data:{
							url:file
						}
					}
				})
			}
			
		})
	},

	/**
	 * @description 使用地址通过高德webService获取地理编码 
	 * @param {Object} addStr
	 */
	getGeocodeByAdd(addStr, city) {
		return new Promise((sucess, fail) => {
			uni.request({
				url: 'https://restapi.amap.com/v3/geocode/geo',
				method: 'get',
				dataType: 'json',
				data: {
					address: addStr,
					output: 'json',
					key: '72281bbc662423d2b0fc09da51eda85e'
				},
				success: function(res) {
					sucess(instance)
				}
			})
		})
	},
	/**
	 * @description  根据经纬度坐标拉去周边商住建筑
	 * @param {Object} longlat
	 */
	getFujinByLongAndLat(longlat) {
		return new Promise(resolve => {
			uni.request({
				url: 'https://restapi.amap.com/v3/geocode/regeo',
				method: 'get',
				dataType: 'json',
				data: {
					location: longlat,
					output: 'json',
					key: '72281bbc662423d2b0fc09da51eda85e',
					extensions: 'all',
					radius: 500
				},
				success: (res) => {
					resolve(res)
				},
				fail: (res) => {
					console.log(res);
				}
			})
		})
	},
	/**
	 * @根据经纬度获取地图静态图片
	 * @param {Object} longlat
	 * @param {Object} size
	 */
	getMapImg(longlat, size) {
		return 'https://restapi.amap.com/v3/staticmap?markers=-1,https://img.hawklu.com/blogImg/2019/11/dw2-1.png,0:' +
			longlat + '&size=' + size + '&scale=2&key=72281bbc662423d2b0fc09da51eda85e'
	},
	
	
	
	
	/**
	 * @description 商家入驻提交或修改资料
	 * @param {Object} postData
	 * postData 格式
	 * 	"userId":2,
		"type":1,	1企业 2个人
		"name":"学而思",		//企业名
		"realname":"小红",	//个人姓名/法人姓名
		"cardNo":"4206251101012122",	//个人/法人身份证号
		"eduCerti":"http://www.ddsf.sd/1.png",	//学历
		"certi":"http://www.ddsf.sd/1.png",	//营业执照or 教师阻资格证
		"certiNo":"11111",	//营业执照编码  or 教师资格证编码
		"cardz":"http://www.ddsf.sd/1.png",	//身份证正面
		"cardf":"http://www.ddsf.sd/1.png"	//身份证反面
	 */
	settledIn(postData) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/user/join/submit.do',
				method: 'post',
				data: postData
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过用户ID获取入驻进度
	 * @param {Object} userId
	 */
	getSettledById(userId) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/user/join/process.do',
				method: 'post',
				data: {
					userId: userId
				}
			})
			resolve(instance)
		})
	},
	
	/**
	 * @description 通过用户ID获取门店列列表
	 * @param {Object} userId
	 */
	getShopListByUserId(userId) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/list.do',
				method: 'post',
				data: {
					userId: userId
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过店铺ID获取店铺详细信息
	 * @param {Object} shopId
	 */
	getShioDetalById(shopId) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/detail.do',
				method: 'post',
				data: {
					id: shopId
				}
			})
			resolve(instance)
		})
	},

	
	/**
	 * @description 添加店铺
	 * @param {Object} shopData
	 * shopData 说明
	 * 	"userId":2,		//用户ID
		"address":"太平南路115号",		//详细地址
		"name":"学而思大行宫点",			//店铺名
		"phone":"025-11998989",		//店铺联系方式
		"longi":231.232,		//纬度
		"lati":112.32,			//经度
		"logoName":"学而思",		//品牌简称
		"logo":"http://www.ddsf.sd/1.png",		//店铺logo
		"areaId":2,		//区ID
		"streetId":1,	//商圈ID
		"realname":"小红",		//法人/个人姓名
		"cardNo":"4206251101012122",	//法人/个人身份证号
		"eduCerti":"http://www.ddsf.sd/1.png",	//学历
		"certi":"http://www.ddsf.sd/1.png",	//营业执照/教师资格证
		"certiNo":"11111",		//营业执照码 / 教师资格证码
		"cardz":"http://www.ddsf.sd/1.png",	//身份证正面
		"cardf":"http://www.ddsf.sd/1.png"	//身份证反面
	 */
	addShop(shopData) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/save.do',
				method: 'post',
				data: shopData
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过店铺ID获取店铺详情
	 * @param {Object} shopId
	 */
	getShopDetailById(shopId) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/detail.do',
				method: 'post',
				data: {
					id: shopId
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取/查询订单列表
	 * @param {Object} opt
	 * opt格式
	 * "orderNo":"",	//订单号
		"storeId":8,	//店铺ID 必填
		"status":0,		//状态
		"page_no":1,	//第几页
		"page_size":10	//每页数量
	 */
	getOrderList(opt) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/list.do',
				method: 'post',
				data: opt
			})
			resolve(instance)
		})
	},
	/**
	 * @description 根据用户ID获取班级列表
	 * @param {Object} userId
	 */
	getClassList(_data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/checkin/class/list.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过班级ID获取考情记录
	 * @param {Object} classId
	 */
	getClassCheckListById(classId) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/checkin/list.do',
				method: 'post',
				data: {
					class_id: classId
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过班级id获取学生列表
	 * @param {Object} classId
	 */
	getClassStudent(classId) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/checkin/student/list.do',
				method: 'post',
				data: {
					classId: classId
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 创建考勤
	 * @param {Object} data
	 */
	createCheckWork(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/checkin/add.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取考勤明细
	 * @param {Object} batch_id
	 */
	getCheckWorkDetail(batch_id) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/checkin/detail.do',
				method: 'post',
				data: {
					batch_id: batch_id
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 修改考勤
	 * @param {Object} batch_id
	 */
	editCheckWork(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/checkin/update.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过店铺ID获取财务信息
	 * @param {Object} sid
	 */
	getAssetInfoBySid(sid) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/finance/info.do',
				method: 'post',
				data: {
					store_id: sid
				}
			})
			resolve(instance)
		})
	},
	/**获取提现记录
	 * @param {Object} data
	 */
	getReflectList(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/fetch/list.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 提现
	 * @param {Object} data
	 */
	ReflectMoney(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/fetch.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过ID获取提现详情
	 * @param {Object} id
	 */
	getReflectDetail(id) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/fetch/detail.do',
				method: 'post',
				data: {
					id: id
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 订单添加备注
	 * @param {Object} data
	 */
	remarkOrder(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/add_memo.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 添加分班标签
	 * @param {Object} data
	 * data:{
		 order_id		//订单编号
		 label		//标签内容
	 }
	 */
	addClassLabel(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/add_label.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过订单ID获取订单详情
	 * @param {Object} oid
	 */
	getOrderDetailById(oid) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/detail.do',
				method: 'post',
				data: {
					orderNo: oid
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取退款订单详情
	 * @param {Object} rid
	 */
	getRefundOrderDetail(rid) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/refund/detail.do',
				method: 'post',
				data: {
					refundId: rid
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取订单统计数量
	 * @param {Object} sid
	 */
	getOrderCount(sid) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/stat.do',
				method: 'post',
				data: {
					storeId: sid
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取店铺经营数据
	 * @param {Object} data
	 * data 字段
	 * type 1今天 2昨天 3七天
	 * storeId 店铺id
	 */
	getManageData(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/store/stat/list.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 拒绝退款
	 * @param {Object} data
	 * data 字段说明
	 * orderId 订单号
	 * operId	//操作者用户ID
	 * refundId		//退款编号
	 * status  4
	 * reason		说明
	 * type 		//原因值
	 * res:[{
		 type:1    1图片			2视屏
		 url:    图片或视屏地址
	 }]
	 */
	refusalRefund(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/handle/add.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 同意退款
	 * @param {Object} data
	 * data 字段
	 * "orderId":1,		//订单编号
		"operId":2,		//退款编号
		"status":11		//状态
	 */
	agreeRefund(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/handle/add.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取售后服务记录
	 * @param {Object} data
	 * "refundId":5,
		"page_no":1,
		"page_size":10
	 */
	getAfterSaleList(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/handle/list.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 退款订单卖家申请介入
	 * @param {Object} data
	 * data 字段
	 * orderId 订单编号
	 * operId  商家用户ID
	 * status  商家为7
	 * refundId
	 */
	applyIntervention(data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/handle/add.do',
				method: 'post',
				data: data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 核销体验码
	 * @param {Object} code
	 */
	validCode(_data) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/order/valid_code.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 根据商品ID获取商品详情
	 * @param {Object} gid 商品id
	 */
	getGoodDtById(gid){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/course/detail.do',
				method: 'post',
				data: {
					id: gid
				}
			})
			resolve(instance)
		})
	},
	getInitZation(){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/common/init.do',
				method: 'post',
				data: {}
			})
			resolve(instance)
		})
	},
	/**
	 * @description  修改订单价格
	 * @param {Object} _data
	 */
	editOrderPrice(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/order/modifyPrice.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取评价学员列表
	 * @param {Object} _data
	 * batch_id
	 */
	apiGetEvaluateList(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/checkin/comment/list.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 添加评价
	 * @param {Object} _data
	 */
	apiAddEvaluate(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/checkin/comment/update.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 删除评价
	 * @param {Object} _data
	 */
	apiDelEvaluate(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/checkin/comment/delete.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取点名规则
	 * @param {Object} _data
	 */
	apiGetRollCallRule(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/checkin/timeable/list.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**
	 * @description 获取某一天课表考勤状态
	 * @param {Object} _data
	 */
	apiGetGetRollCallStatus(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/checkin/timeable/stat.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**获取请假记录
	 * @param {Object} context
	 * @param {Object} _data
	 */
	apiGetLeaveList(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/leave/list.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	},
	/**获取老师工作台统计数据
	 * @param {Object} _data
	 */
	apiGetTeacherCount(_data){
		return new Promise(resolve=>{
			let r = Request();
			let instance = r.request({
				url: '/store/stat/teacher.do',
				method: 'post',
				data: _data
			})
			resolve(instance)
		})
	}

}
